package hotciv.variants;

import hotciv.common.Utility;
import hotciv.framework.BattleStrategy;
import hotciv.framework.Game;
import hotciv.framework.Position;
import hotciv.framework.Randomizer;
import hotciv.framework.Unit;

public class EpsilonBattleStrategy implements BattleStrategy
{

	
	private Randomizer d1;
	private Randomizer d2;
	
	public EpsilonBattleStrategy(Randomizer d1, Randomizer d2)
	{
		this.d1 = d1;
		this.d2 = d2;
	}
	
	@Override
	public boolean determineBattle( Game game, Position battlefield, Unit attacker )
	{
		int atcStr = attacker.getAttackingStrength();
		atcStr += Utility.getFriendlySupport(game, battlefield, attacker.getOwner());
		atcStr *= Utility.getTerrainFactor(game, battlefield);
		
		int atcDef = game.getUnitAt(battlefield).getDefensiveStrength();
		atcDef += Utility.getFriendlySupport(game, battlefield, game.getUnitAt(battlefield).getOwner());
		atcDef *= Utility.getTerrainFactor(game, battlefield);
		int att = atcStr * d1.getRand();
		int def = atcDef * d2.getRand();
		//System.out.println("Attack: ("+atcStr+") "+att+" Defence: ("+atcDef+") "+def);
		return (att > def);		
	}
	
}
